<template>
  <div class="login">
    <div class="left">
      <div class="login-title">
        <img class="t1" src="@/assets/img/login_logo.png" alt="" />
        <span class="t2">黑马面面</span>
        <div class="t3"></div>
        <span class="t4">用户登录</span>
      </div>
      <!-- el-form -->
      <el-form :model="form" class="form" :rules="rules" ref="form">
        <el-form-item prop="phone">
          <el-input
            placeholder="请输入手机号"
            prefix-icon="el-icon-user"
            v-model="form.phone"
          >
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
            v-model="form.password"
            show.password
          >
          </el-input>
        </el-form-item>
        <!-- 栅栏 -->
        <el-form-item prop="code">
          <el-row>
            <el-col :span="16">
              <el-input
                v-model="form.code"
                placeholder="请输入验证码"
                prefix-icon="el-icon-key"
              >
              </el-input>
            </el-col>
            <el-col :span="8">
              <img
                :src="imgurl"
                class="login-code"
                alt=""
                @click="imgbtn"
              />
            </el-col>
          </el-row>
        </el-form-item>
        <!-- 勾选协议 -->
        <el-form-item class="mt" prop="ispass" > 
          <el-checkbox  :label="true" v-model="form.ispass">
            我已阅读并同意<el-link type="primary" class="tex">用户协议</el-link
            >和<el-link type="primary" class="tex">隐私条款</el-link>
          </el-checkbox>
        </el-form-item>
        <!-- 按钮 -->
        <el-form-item>
          <el-button type="primary" class="btn" @click="goLogin"
            >登陆</el-button
          >
          <br />
          <el-button type="primary" class="btn" @click="open">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
    <img class="right" src="@/assets/img/login.png" alt=""/>
    <register ref="register"></register>
  </div>
</template>

<script>
import register from './register'
export default {
  components:{
    register
  },
  data() {
    return {
      imgurl:"",
      form: {
        phone: "",
        password: "",
        code: "",
        ispass: [],
        
      },
      rules: {
        phone: [
          { required: true, message: "请输入手机号", trigger: "change" },
          { min: 11, max: 11, message: "请输入11位手机号", trigger: "change" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "change" },
          { min: 6, max: 12, message: "请输入6-12位密码", trigger: "change" },
        ],
        code: [
          { required: true, message: "请输入验证码", trigger: "change" },
          { min: 4, max: 4, message: "请输入4位验证码", trigger: "change" },
        ],
        ispass:[
          { required: true, message: "请勾选协议", trigger: "change" },
        ]
        
      },
    };
  },
  methods: {
    goLogin() {
      this.$refs.form.validate((result) => {
        if (result) {
          this.$message.success("验证成功");
        } else {
          this.$message.error("验证失败");
        }
      });
    },
    open(){
      this.$refs.register.isShow=true
    },
    imgbtn(){ 
      this.imgurl=" http://autumnfish.cn/heimamm/public/captcha?type=login&ssadasfs=" + Math.random()*99
    }
  },
  created() {
    this.imgbtn()
  }
  
};
</script>

<style lang="less">
.login {
  height: 100%;
  background: linear-gradient(#1493fa 28%, #01c6fa 96%);
  display: flex;
  align-items: center;
  justify-content: space-around;

  .left {
    width: 478px;
    height: 550px;
    padding: 42px;
    background-color: #f5f5f5;

    .login-title {
      display: flex;
      align-items: center;

      .t1 {
        width: 25px;
        height: 18px;
        margin-top: 5px;
      }
      .t2 {
        font-size: 24px;
        font-family: SourceHanSansCN Regular, SourceHanSansCN Regular-Regular;
        font-weight: 400;
        text-align: left;
        color: #0c0c0c;
        margin: 0 14px;
      }
      .t3 {
        width: 1px;
        height: 28px;
        background: #c7c7c7;
        margin-right: 12px;
      }
      .t4 {
        font-size: 22px;
        font-family: PingFangSC Regular, PingFangSC Regular-Regular;
        font-weight: 400;
        text-align: left;
        color: #0c0c0c;
      }
    }
    .login-code {
      width: 100%;
      height: 40px;
    }
    .form {
      margin-top: 30px;

      .btn {
        display: block;
        width: 100%;
      }
      .btn:nth-child(2) {
        margin-top: 2px;
      }
      .tex {
        margin-top: -3px;
      }
      .mt {
        margin-top: 30px;
      }
    }
  }
}
</style>
